var SearchForm = function () {
  var template = /* html */ `
    <div class="search-form" v-loading.fullscreen.lock="loading">
      <el-form inline size="medium" label-width="auto">
        <el-form-item label="设备型号">
          <el-input v-model="search.machineModel" class="search-input"></el-input>
        </el-form-item>
        <el-form-item label="故障部件">
          <el-select filterable v-model="search.workBrokenPart" class="search-input">
            <el-option v-for="part in workBrokenPartList" :key="part" :value="part"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="故障描述">
          <el-input v-model="search.workBrokenDescription" class="search-input"></el-input>
        </el-form-item>
        <el-form-item label="解决方案">
          <el-input v-model="search.workBrokenSolveWay" class="search-input"></el-input>
        </el-form-item>
        <el-form-item label="状态">
            <el-select v-model="search.status" class="search-input">
              <el-option v-for="item in statusList" :key="item.value" :value="item.value" :label="item.label"></el-option>
            </el-select>
          </el-form-item>
      </el-form>
    </div>
  `;

  return {
    props: {
      search: {
        type: Object,
        required: true
      },
      dropdownOption: {
        type: Object,
        default: function () {
          return {};
        }
      }
    },

    data: function () {
      return {
        loading: false,
        workBrokenPartList: [],
        statusList: i18n.getDropDown('machineRepair.repairRecord.status', [1, 0])
      };
    },

    created: function () {
      this.loading = true;
      var self = this;
      this.setWorkBrokenPartList().then(function () {
        self.loading = false;
      }).catch(function () {
        self.loading = false;
      });
    },

    methods: {
      setWorkBrokenPartList: function () {
        var dropdownOption = this.dropdownOption;
        var workBrokenPartList = dropdownOption.workBrokenPartList;
        if (workBrokenPartList !== undefined) {
          this.workBrokenPartList = workBrokenPartList;
          return Promise.resolve(workBrokenPartList);
        }

        var self = this;
        return ajaxRequest('html/createOrder/json/brokenPart.json', {}, false).then(function (res) {
          var workBrokenPartList = res.rows;
          workBrokenPartList = _.map(workBrokenPartList, 'text');
          dropdownOption.workBrokenPartList = workBrokenPartList;
          self.workBrokenPartList = workBrokenPartList;
          return workBrokenPartList;
        });
      }
    },

    template: template
  };
}();
